﻿using Architecture.API.Application.TraceabilityCommand.BreedCommand;
using Architecture.API.Application.TraceabilityCommand.ShoppingCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.Domain.BreedDomain;
using Traceability.Domain.TraceabilityDto;

namespace Architecture.API.Controllers
{
    /// <summary>
    /// API控制器--养殖
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BreedManagementController : ControllerBase
    {
        /// <summary>
        /// 命令在线
        /// </summary>
        protected readonly IMediator mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">命令在线</param>
        public BreedManagementController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加养殖信息
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddBreedInfo(AddBreedCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 显示养殖信息列表
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回商品信息</returns>
        [HttpPost]
        public async Task<ApiResult<List<Breed>>> ShowBreedList(ShowBreedCommand command)
        {
            ApiResult<List<Breed>> result = new ApiResult<List<Breed>>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 反填养殖信息
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回商品信息</returns>
        [HttpPost]
        public async Task<ApiResult<Breed>> BackInfoBreed(BreedReverseCommand command)
        {
            ApiResult<Breed> result = new ApiResult<Breed>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 修改养殖信息
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回商品信息</returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateBreed(UpdateBreedCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

    }
}
